const express = require('express')
const app = express()

// 指定动态视图的模板引擎用ejs
app.set("view engine", "ejs");
// 指定ejs页面的目录
app.set("views", "./views");

const products = [
  {id: 1, name: 'AAA', price: 1212},
  {id: 2, name: 'BBB', price: 2323},
  {id: 3, name: 'CCC', price: 3434}
]
app.get('/products', (req, res) => {
  res.render('test', {username: 'admin', products})  // 对象中的属性在模板中可以直接访问
})

app.listen('3000',  () => {
  console.log('服务已启动: http://localhost:3000')
})